package com.probox.modules.controller.platfom;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.platfom.PlatformFreight;
import com.probox.common.entity.service.platfom.IPlatformFreightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 平台邮费设置Controller
 *
 * @author usoft
 * @date 2021-06-28
 */
@RestController
@RequestMapping("/platform/freight")
public class PlatformFreightController extends BaseController {
    @Autowired
    private IPlatformFreightService platformFreightService;

    /**
     * 查询平台邮费设置列表
     */
    @PreAuthorize(hasPermi = "platform:freight:list")
    @GetMapping("/list")
    public TableDataInfo list(PlatformFreight platformFreight) {
        startPage();
        List<PlatformFreight> list = platformFreightService.queryList(platformFreight);
        return getDataTable(list);
    }

    /**
     * 导出平台邮费设置列表
     */
    @PreAuthorize(hasPermi = "platform:freight:export")
    @Log(title = "平台邮费设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlatformFreight platformFreight) throws IOException {
        List<PlatformFreight> list = platformFreightService.queryList(platformFreight);
        ExcelUtil<PlatformFreight> util = new ExcelUtil<PlatformFreight>(PlatformFreight.class);
        util.exportExcel(response, list, "平台邮费设置数据");
    }

    /**
     * 获取平台邮费设置详细信息
     */
    @PreAuthorize(hasPermi = "platform:freight:query")
    @GetMapping(value = "/{freightUid}")
    public AjaxResult getInfo(@PathVariable("freightUid") Long freightUid) {
        return AjaxResult.success(platformFreightService.selectPlatformFreightById(freightUid));
    }



    /**
     * 修改平台邮费设置
     */
    @PreAuthorize(hasPermi = "platform:freight:edit")
    @Log(title = "平台邮费设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlatformFreight platformFreight) {
        return toAjax(platformFreightService.updatePlatformFreight(platformFreight));
    }

    /**
     * 删除平台邮费设置
     */
    @PreAuthorize(hasPermi = "platform:freight:remove")
    @Log(title = "平台邮费设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{freightUids}")
    public AjaxResult remove(@PathVariable Long[] freightUids) {
        return toAjax(platformFreightService.deletePlatformFreightByIds(freightUids));
    }
}
